package ${basePackage}.common;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理。
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public BaseResponse<Void> handleBusinessException(BusinessException exception) {
        ErrorCode errorCode = exception.getErrorCode();
        String message = exception.getMessage();
        log.warn("业务异常: {}", message);
        return ResultUtils.error(errorCode, message);
    }

    @ExceptionHandler(Exception.class)
    public BaseResponse<Void> handleException(Exception exception) {
        log.error("系统异常", exception);
        return ResultUtils.error(ErrorCode.OPERATION_ERROR, "系统异常，请稍后重试");
    }
}

